package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysConsultantFeeSort;
import com.hl.sfzy.service.SysConsultantFeeSortService;
import com.hl.sfzy.service.SysConsultantFeeSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: sfzy
 * @ClassName SysConsultantFeeSortController
 * @description:
 * @author: xiaoyang
 * @create: 2024-07-11 21:14
 * @Version 1.0
 **/
@RestController
public class SysConsultantFeeSortController {
    @Autowired
    private SysConsultantFeeSortService sysConsultantFeeSortService;

    @PostMapping("/sysConsultantFeeSort")
    public Result add(@RequestBody SysConsultantFeeSort sysConsultantFeeSort) {
        int num = sysConsultantFeeSortService.add(sysConsultantFeeSort);
        return num > 0 ? Result.success() : Result.error();
    }

    /*通过id删除*/
    @DeleteMapping("/sysConsultantFeeSort/{id}")
    public Result removeById(@PathVariable("id") Integer id) {
        int num = sysConsultantFeeSortService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    /*通过id批量删除*/
    @DeleteMapping("/sysConsultantFeeSort")
    public Result removeBatch(Integer[] ids) {
        int num = sysConsultantFeeSortService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    /*修改*/
    @PutMapping("/sysConsultantFeeSort")
    public Result edit(@RequestBody SysConsultantFeeSort sysConsultantFeeSorts) {
        int num = sysConsultantFeeSortService.edit(sysConsultantFeeSorts);
        return num > 0 ? Result.success() : Result.error();
    }

    /*查询所有*/
    @GetMapping("/sysConsultantFeeSort")
    public Result findAll(SysConsultantFeeSort sysConsultantFeeSort) {
        List<SysConsultantFeeSort> list = sysConsultantFeeSortService.find(sysConsultantFeeSort);
        return Result.success(list);
    }

    /*根据id查询*/
    @GetMapping("/sysConsultantFeeSort/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        SysConsultantFeeSort assess = sysConsultantFeeSortService.findById(id);
        return Result.success(assess);
    }
    /*分页*/
    @GetMapping("/sysConsultantFeeSort/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           SysConsultantFeeSort sysConsultantFeeSort) {
        Map<String, Object> map = sysConsultantFeeSortService.findPage(pageNum, pageSize, sysConsultantFeeSort);
        return Result.success(map);

    }
}